package cn.tedu.sp04.service;

import cn.tedu.sp01.pojo.Item;
import cn.tedu.sp01.pojo.Order;
import cn.tedu.sp01.pojo.User;
import cn.tedu.sp01.service.OrderService;
import cn.tedu.sp01.util.JsonResult;
import cn.tedu.sp04.feign.ItemClient;
import cn.tedu.sp04.feign.UserClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName orderServiceImpl
 * @Description:类描述
 * @Author Tedu
 * @Date 2021/6/22 15:45
 * @Version V1.0
 **/
@Slf4j
@Service
public class OrderServiceImpl implements OrderService {
    @Autowired
    private ItemClient itemClient;
    @Autowired
    private UserClient userClient;




    @Override
    public Order getOrder(String id) {
        log.info("获取订单,id= "+id);
        JsonResult<List<Item>> items=itemClient.getItems(id);
        JsonResult<User> user=userClient.getUser(8);
        //TODO:远程调用
        Order order = new Order();
        order.setId(id)
                .setUser(user.getData())
                .setItems(items.getData());
        return order;
    }

    @Override
    public void addOrder(Order order) {
        log.info("添加订单,order= "+order);
        itemClient.decreaseNumber(order.getItems());
        userClient.addScore(order.getUser().getId(),1000);

    }
}
